package P06_辅助类;

import java.util.concurrent.CountDownLatch;

public class P01_CountDownLatch {

    /**
     * 6个同学陆续离开教室之后，班长锁门
     * @param args
     */
//    public static void main(String[] args) {
//        for (int i = 0; i < 6; i++) {
//            new Thread(() ->{
//                System.out.println(Thread.currentThread().getName()+ "号同学离开了教室");
//            },String.valueOf(i+1)).start();
//        }
//        System.out.println(Thread.currentThread().getName() + " 班长锁门");
//    }

    /**
     * 6个同学陆续离开教室之后，班长锁门
     * @param args
     */
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 0; i < 6; i++) {
            new Thread(() ->{
                System.out.println(Thread.currentThread().getName()+ "号同学离开了教室");
                countDownLatch.countDown();
            },String.valueOf(i+1)).start();
        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName() + " 班长锁门");
    }
}
